package org.example.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.naming.ldap.PagedResultsControl;
import java.util.HashSet;


@Data
@AllArgsConstructor
@NoArgsConstructor
public class AuthInfo {
    private boolean enable;
    private boolean token;
    private String tokenInfo;
    private HashSet<String> roles;
    private int level;
    private int authType;


    public AuthInfo roleAdd(String role){
        if(this.roles==null)
            this.roles = new HashSet<>();
        this.roles.add(role);
        return this;
    }

    @Override
    public String toString() {
        return "AuthInfo{" +
                "enable=" + enable +
                ", token=" + token +
                ", tokenInfo='" + tokenInfo + '\'' +
                ", roles=" + roles +
                ", level=" + level +
                '}';
    }

    public boolean hasAuth(String role){
        return this.roles.contains(role);
    }

    public boolean levelCompare(int level){
        return this.level>=level;
    }
}
